package com.mxin.ui.list

import com.mxin.ui.global.UIConstants

data class Page(val page:Int = 0, val pageSize:Int = UIConstants.PageSize){


    private lateinit var prevPage : Page

    private lateinit var nextPage : Page

    private var head : Page = this

    fun head():Page = head

    fun prev():Page{
        return if(::prevPage.isInitialized){
            prevPage
        }else{
            getPrevPage().also {
                it.head = this.head
                it.nextPage = this
                prevPage = it
            }
        }
    }

    fun next():Page{
        return if(::nextPage.isInitialized){
            nextPage
        }else{
            getNextPage().also {
                it.head = this.head
                it.prevPage = this
                nextPage = it
            }
        }
    }

    //下一页
    private fun getNextPage():Page = Page(page+1, pageSize)

    private fun getPrevPage():Page = Page(page-1, pageSize)

}

